var wstj = {
	initWstj:function(slrq,swjgUuid,sort1,sort2){
	//alert(slrq +' '+ swjgUuid +' '+sort1+' '+sort2　);
		$.ajax({
            type: "GET",
            url: config.baseURL + "reportWstj/wstjList.action",
            cache:false,
            dataType: "json",
            data : {
				"swjgUuid":swjgUuid,
                "wszllzhzd.slsj":slrq,
                "sort1":sort1,
                "sort2":sort2,
                "page":1,
                "pagesize":1
            },
            success: function(data){
                if(data.result.success==true){
                	$("#div1").show();
                	$("#div2").show();
                	$("#div3").show();
                	//var wstjtr = '';
                	$('#tbody_wstjList').empty();
                	//首页
            		$.each(data.wstj, function(index, obj) {
						if(index <10){
							wstjtr ='<tr height="35px;"><td><span style="font-size:10">'+obj.nsrsbh+'</span></td><td><span style="font-size:10">'+obj.nsrmc+'</span></td><td><span style="font-size:10">'+obj.swsxmc+'</span></td><td>'+obj.slsj+'</td><td>'+obj.slr+
            				'</td><td>'+obj.xbsx+'</td><td><span style="font-size:10">'+obj.cbbm+'</span></td><td>'+obj.cbr+'</td><td>　　　</td><td>　　　</td><td>　　　</td><td>　　　</td><td>　　　</td></tr>';
							$('#tbody_wstjList').append(wstjtr);
						}
            		});

   //分页------------------------------------------------------------------------------------ 
					var pageIndex = 1;
                	var pagesize = 10;
            		//取得总条数
                	$('#lblToatl').html(data.wstj.length);
                	//取当前页数
                	$('#lblCurent').html(pageIndex);
                	//取得总页数
                	var totalPage = Math.floor(data.wstj.length / 10 +1) ;
                	$('#lblPageCount').html(totalPage);
                	
                	var wstjth = '';
                		
                	
                	$("#first").click(function() { 
						pageIndex = 1; 
						$("#lblCurent").text(1); 
						$('#tbody_wstjList').html(wstjth);
						$.each(data.wstj, function(index, obj) {
							if(index < pageIndex * pagesize){
								wstjtr ='<tr height="35px;"><td><span style="font-size:10">'+obj.nsrsbh+'</span></td><td><span style="font-size:10">'+obj.nsrmc+'</span></td><td><span style="font-size:10">'+obj.swsxmc+'</span></td><td>'+obj.slsj+'</td><td>'+obj.slr+
                				'</td><td>'+obj.xbsx+'</td><td><span style="font-size:10">'+obj.cbbm+'</span></td><td>'+obj.cbr+'</td><td>　　　</td><td>　　　</td><td>　　　</td><td>　　　</td><td>　　　</td></tr>';
								$('#tbody_wstjList').append(wstjtr);
							}
                		});
					}); 

                	$("#prev").click(function() { 
                		
                		if(pageIndex > 1){
                			pageIndex = pageIndex -1;
                		}
						$("#lblCurent").text(pageIndex); 
						$('#tbody_wstjList').html(wstjth);
						$.each(data.wstj, function(index, obj) {
							if(index <pageIndex * pagesize && index >= (pageIndex-1)*pagesize ){
								wstjtr ='<tr height="35px;"><td><span style="font-size:10">'+obj.nsrsbh+'</span></td><td><span style="font-size:10">'+obj.nsrmc+'</span></td><td><span style="font-size:10">'+obj.swsxmc+'</span></td><td>'+obj.slsj+'</td><td>'+obj.slr+
                				'</td><td>'+obj.xbsx+'</td><td><span style="font-size:10">'+obj.cbbm+'</span></td><td>'+obj.cbr+'</td><td>　　　</td><td>　　　</td><td>　　　</td><td>　　　</td><td>　　　</td></tr>';
								$('#tbody_wstjList').append(wstjtr);
							}
                		});
					});
                	
                	$("#next").click(function() { 
                		
                		if(pageIndex < totalPage){
                			pageIndex = pageIndex +1;
                		}
						$("#lblCurent").text(pageIndex); 
						$('#tbody_wstjList').html(wstjth);
						$.each(data.wstj, function(index, obj) {
							if(index >= (pageIndex-1) * pagesize && index < pageIndex*pagesize ){
								wstjtr ='<tr height="35px;"><td><span style="font-size:10">'+obj.nsrsbh+'</span></td><td><span style="font-size:10">'+obj.nsrmc+'</span></td><td><span style="font-size:10">'+obj.swsxmc+'</span></td><td>'+obj.slsj+'</td><td>'+obj.slr+
                				'</td><td>'+obj.xbsx+'</td><td><span style="font-size:10">'+obj.cbbm+'</span></td><td>'+obj.cbr+'</td><td>&nbsp;</td><td>&nbsp;</td><td>　　　</td><td>　　　</td><td>　　　</td></tr>';
								$('#tbody_wstjList').append(wstjtr);
							}
                		});
					});
                	
                	$("#last").click(function() {
						pageIndex = totalPage; 
						
						$("#lblCurent").text(pageIndex); 
						$('#tbody_wstjList').html(wstjth);
						$.each(data.wstj, function(index, obj) {
							if(index < pageIndex * pagesize && index >= (pageIndex-1) * pagesize){
								wstjtr ='<tr height="35px;"><td><span style="font-size:10">'+obj.nsrsbh+'</span></td><td><span style="font-size:10">'+obj.nsrmc+'</span></td><td><span style="font-size:10">'+obj.swsxmc+'</span></td><td>'+obj.slsj+'</td><td>'+obj.slr+
                				'</td><td>'+obj.xbsx+'</td><td><span style="font-size:10">'+obj.cbbm+'</span></td><td>'+obj.cbr+'</td><td>　　　</td><td>　　　</td><td>　　　</td><td>　　　</td><td>　　　</td></tr>';
								$('#tbody_wstjList').append(wstjtr);
							}
                		});
					}); 
                	
   //---------------------------------------------------------------------------------------             	
                	
                }else{
                    //alert("当天无数据");
               		$('#tbody_wstjList').empty();
               		/*取得总条数                	$('#lblToatl').html(data.wstj.length);
                	取当前页数                	$('#lblCurent').html(pageIndex);
                	取得总页数                	var totalPage = Math.floor(data.wstj.length / 10 +1) ;
                	$('#lblPageCount').html(totalPage);
                	$("#first").click(function() {});
                	$("#prev").click(function() {});
                	$("#next").click(function() {});
                	$("#last").click(function() {});*/
                	//$("#div1").hide();
                	$("#div2").hide();
                	$("#div3").hide();
                }
            },
            error:function(data){
            	alert('false');
            }
        });
    },
    initCbbm :function (swjgUuid){
    	$(window.parent.document).find("#sort1").empty();
		//var opt = $("<option/>").text('全部').attr("value", 'all');
		var opt = "<option value='all'>全部</option>"
		$(window.parent.document).find("#sort1").append(opt);
		$.ajax({
			type: "GET",
	        url: config.baseURL + "reportWstj/getCbbmList.action",
	        cache:false,
	        dataType: "json",
	        data : {
				"swjgUuid":swjgUuid
	        },
	        success: function(data){
	        	if(data.result.success==true){
	        		$.each(data.list, function(index, menu) {
        			 //opt = $("<option/>").text(menu).attr("value", menu); 
        			 opt = '<option value='+menu+'>'+menu+'</option>';
        			 $(window.parent.document).find("#sort1").append(opt);
        		});
        		$(window.parent.document).find("#sort1").change(function(){ 
        			wstj.initWstj($(window.parent.document).find('#taxpayerId').val(),$(window.parent.document).find("#swjg").val(),$(window.parent.document).find("#sort1").val(),$(window.parent.document).find("#sort2").val());
				});
	        	}
	        }
		});
	},
	initSwjg :function (swjgUuid){
		var bigSwjgUuid;
		$.ajax({
			type: "GET",
	        url: config.baseURL + "report/listSwjgBySuperId.action",
	        cache:false,
	        dataType: "json",
	        data : {
				"superSwjgUuid":swjgUuid
	        },
	        success: function(data){
	        	if(data.result.success==true){
	        		$(window.parent.document).find("#swjg").empty();
	        		if(data.result.resultMsg == 'more'){
	        			bigSwjgUuid = $.cookie('swjgUuid');
	        			$(window.parent.document).find("#cbbm").hide();
	        			//var opt = $("<option/>").text('全部').attr("value", 'all');
	        			var opt = "<option value='all'>全部</option>";
	        			$(window.parent.document).find("#swjg").append(opt);
		        		$.each(data.list, function(index, menu) {
	        				//opt = $("<option/>").text(menu[1]).attr("value", menu[0]); 
	        				opt = '<option value='+menu[0]+'>'+menu[1]+'</option>';
	        			 	$(window.parent.document).find("#swjg").append(opt);
	        			});
		        		$(window.parent.document).find("#swjg").change(function(){
		        			if($(window.parent.document).find("#swjg").val() == 'all'){
		        				swjgUuid = bigSwjgUuid;
		        				$(window.parent.document).find("#cbbm").hide();
		        			}else{
		        				$(window.parent.document).find("#cbbm").show();
		        				swjgUuid = $(window.parent.document).find("#swjg").val();
		        			}
		        			wstj.initCbbm(swjgUuid);
		        			wstj.initWstj($(window.parent.document).find('#taxpayerId').val(),swjgUuid,$(window.parent.document).find("#sort1").val(),$(window.parent.document).find("#sort2").val());
						});
		        		$(window.parent.document).find("#sort1").change(function(){ 
		        			//wstj.initWstj($(window.parent.document).find('#taxpayerId').val(),$(window.parent.document).find("#swjg").val(),$(window.parent.document).find("#sort1").val(),$(window.parent.document).find("#sort2").val());
						});
		        	}else{
		        		//var opt = $("<option/>").text( $.cookie('swjgName')).attr("value", swjgUuid);
		        		var opt = '<option value='+swjgUuid+'>'+$.cookie('swjgName')+'</option>';
	        			$(window.parent.document).find("#swjg").append(opt);
		        	}
	        	}else{
	        		//var opt = $("<option/>").text( $.cookie('swjgName')).attr("value", swjgUuid);
	        		var opt = '<option value='+swjgUuid+'>'+$.cookie('swjgName')+'</option>';
	        		$(window.parent.document).find("#swjg").append(opt);
	        	}
	        }
		});
	}
};


